package com.uton.rfidcontroller.common.net;

import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.uton.rfidcontroller.model.base.BaseModel;

import java.lang.reflect.Type;

/**
 * Created by 王家宝 on 2017/8/30.
 * Email:639586819@qq.com
 * Tel:18241150668
 */
public class UserTypeAdapter implements JsonDeserializer<BaseModel> {

    @Override
    public BaseModel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        if (json.isJsonObject()) {
            Gson gson = new Gson();
            return gson.fromJson(json, BaseModel.class);
        } else {
            return null;
        }
    }
}
